<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>改变原数组的7个方法</title>
</head>
<body>
  <script>
    /*
    改变原数组的7个方法:
      push/unshift
      pop/shift
      reverse
      splice(index, delCount, addElement...)
      sort
    */

    /*
      sort: 排序
      数组对象.sort((x, y) => x - y)： 从小到大
      数组对象.sort((x, y) => y - x): 从大到小
    */

    // let nums = [45, 17, 28, 3, 9]
    // 从小到大
    // nums.sort((x, y) => x - y)
    // console.log(nums)
    //从大到小
    // let r = nums.sort((x, y) => y - x)
    // console.log(r)
    // console.log(nums)



    let list = [
      {
        id: 9,
        price: 18.8,
        name: '乒乓球拍'
      },{
        id: 20,
        price: 168,
        name: '篮球'
      },{
        id: 6,
        price: 99,
        name: '足球'
      },{
        id: 17,
        price: 138,
        name: '羽毛球'
      }
    ]
    // list.sort((o1, o2) => o1.price - o2.price)
    list.sort((o1, o2) => o2.price - o1.price)
    console.log(list)
  </script>
</body>
</html>